package com.examples.gateway.common;

import lombok.Getter;

/**
 * 经过过滤器后的检查状态
 * @author Dai YaLu
 */
@Getter
public enum CheckState {

    /**
     * 跳过白名单路径
     */
    SUCCESS_SKIP_PATH(204,
            "success.permission.skipPath", "SUCCESS_SKIP_PATH"),
    /**
     * 访问公开接口
     */
    SUCCESS_PUBLIC_ACCESS(205,
            "success.permission.publicAccess", "SUCCESS_PUBLIC_ACCESS"),
    /**
     * 登录后访问接口
     */
    SUCCESS_LOGIN_ACCESS(206,
            "success.permission.loginAccess", "SUCCESS_LOGIN_ACCESS"),

    /**
     * 超级管理员用户，且接口为非内部接口，允许访问
     */
    SUCCESS_ADMIN(207,
            "success.permission.adminUser", "SUCCESS_ADMIN"),

    /**
     * gateway-helper关闭权限校验，一切请求都允许访问
     */
    SUCCESS_PERMISSION_DISABLED(208,
            "success.permission.disabled", "SUCCESS_PERMISSION_DISABLED"),

    /**
     * 开发者路由，不做权限校验
     */
    SUCCESS_DEVELOPER_ROUTE(209,
            "success.developer.route", "SUCCESS_DEVELOPER_ROUTE"),

    /**
     * 签名接口验证通过，允许访问
     */
    SUCCESS_SIGNATURE_ACCESS(210,
            "success.permission.signAccess", "SUCCESS_SIGNATURE_ACCESS"),

    /**
     * 内部接口禁止访问，只允许服务内部调用
     */
    PERMISSION_WITH_IN(402,
            "error.permission.withinForbidden", "PERMISSION_WITH_IN"),

    /**
     * 该登录用户没有此接口访问权限
     */
    PERMISSION_NOT_PASS(403,
            "error.permission.notPass", "PERMISSION_NOT_PASS"),

    /**
     * 未找到与该请求相匹配的权限
     */
    PERMISSION_MISMATCH(404,
            "error.permission.mismatch",
            "PERMISSION_MISMATCH", "helper.info.permissionNotFound"),

    /**
     * 该登录用户没有在此项目下的此接口访问权限
     */
    PERMISSION_NOT_PASS_PROJECT(405,
            "error.permission.projectNotPass", "PERMISSION_NOT_PASS_PROJECT"),

    /**
     * 该登录用户没有在此组织下的此接口访问权限
     */
    PERMISSION_NOT_PASS_ORG(406,
            "error.permission.organizationNotPass", "PERMISSION_NOT_PASS_ORG"),

    /**
     * 请求头部没有access_token
     */
    PERMISSION_ACCESS_TOKEN_NULL(407,
            "error.permission.accessTokenNull", "PERMISSION_ACCESS_TOKEN_NULL"),

    /**
     * accessToken不合法
     */
    PERMISSION_ACCESS_TOKEN_INVALID(408,
            "error.permission.accessTokenInvalid", "PERMISSION_ACCESS_TOKEN_INVALID"),

    /**
     * accessToken已过期
     */
    PERMISSION_ACCESS_TOKEN_EXPIRED(409,
            "error.permission.accessTokenExpired", "PERMISSION_ACCESS_TOKEN_EXPIRED"),

    /**
     * 通过access_token从oauthServer获取userDetails失败
     */
    PERMISSION_GET_USE_DETAIL_FAILED(410,
            "error.permission.getUserDetailsFromOauthServer", "PERMISSION_GET_USE_DETAIL_FAILED"),

    /**
     * 该项目已经被禁用
     */
    PERMISSION_DISABLED_PROJECT(411,
            "error.permission.projectDisabled", "PERMISSION_DISABLED_PROJECT"),

    /**
     * 该组织已经被禁用
     */
    PERMISSION_DISABLED_ORG(412,
            "error.permission.organizationDisabled", "PERMISSION_DISABLED_ORG"),
    /**
     * 白名单拦截
     */
    PERMISSION_WHITE_LIST_FORBIDDEN(413,
            "error.permission.whiteListForbidden", "PERMISSION_WHITE_LIST_FORBIDDEN"),
    /**
     * 黑名单拦截
     */
    PERMISSION_BLACK_LIST_FORBIDDEN(414,
            "error.permission.blackListForbidden", "PERMISSION_BLACK_LIST_FORBIDDEN"),
    /**
     * 签名认证不通过
     */
    PERMISSION_NOT_PASS_SIGNATURE(415,
            "error.permission.signature", "PERMISSION_NOT_PASS_SIGNATURE"),
    /**
     * 访问的菜单没有API权限
     */
    PERMISSION_MENU_MISMATCH(416,
            "error.permission.menuMismatch", "PERMISSION_MENU_MISMATCH"),
    /**
     * 访问权限层级不匹配
     */
    PERMISSION_LEVEL_MISMATCH(417,
            "error.permission.levelMismatch", "PERMISSION_LEVEL_MISMATCH"),
    /**
     * 分配角色过期
     */
    MEMBER_ROLE_EXPIRED(418,
            "error.permission.memberRoleExpired", "MEMBER_ROLE_EXPIRED"),
    /**
     * 没有角色
     */
    ROLE_IS_EMPTY(419,
            "error.permission.roleIsEmpty", "ROLE_IS_EMPTY"),
    /**
     * 访问的菜单未传递H-Menu-Id
     */
    MENU_MISMATCH(420,
            "error.menuMismatch", "MENU_MISMATCH", "helper.info.menuIdNotNull"),
    /**
     * 重放请求
     */
    REQUEST_REPEAT(425,
            "error.request.repeat", "REQUEST_REPEAT"),

    /**
     * 没有通过API数据权限校验
     */
    API_AUTHORITY(426,
            "error.api-authority", "API_AUTHORITY", "helper.info.apiAuthority"),

    /**
     * 访问过于频繁
     */
    RATE_LIMIT_NOT_PASS(301,
            "error.visit.frequent", "RATE_LIMIT_NOT_PASS"),

    /**
     * gatewayHelper发生异常
     */
    EXCEPTION_GATEWAY_HELPER(501,
            "error.gatewayHelper.exception", "EXCEPTION_GATEWAY_HELPER"),

    /**
     * 无法获取jwt
     */
    EXCEPTION_OAUTH_SERVER(502,
            "error.oauthServer.exception", "EXCEPTION_OAUTH_SERVER"),

    /**
     * 接口异常。项目下的接口路径必须包含project_id
     */
    API_ERROR_PROJECT_ID(503,
            "error.api.projectId", "API_ERROR_PROJECT_ID"),

    /**
     * 接口异常。组织下的接口路径必须包含organization_id
     */
    API_ERROR_ORG_ID(504,
            "error.api.orgId", "API_ERROR_ORG_ID"),

    /**
     * 接口异常。本请求可以同时匹配到多个接口
     */
    API_ERROR_MATCH_MULTIPLY(505,
            "error.api.matchMultiplyPermission", "API_ERROR_MATCH_MULTIPLY"),

    /**
     * 未找到该请求对应的zuul路由，请在路由管理页面添加路由
     */
    PERMISSION_SERVICE_ROUTE(506,
            "error.permission.routeNotFound", "PERMISSION_SERVICE_ROUTE", "helper.info.routeNotFound"),

    /**
     * 未找到该请求对应的zuul路由，请在路由管理页面添加路由
     */
    PERMISSION_SERVICE_INSTANCE(507,
            "error.permission.instanceNotRunning", "PERMISSION_SERVICE_INSTANCE", "helper.info.instanceNotRunning"),

    /**
     * 发生未知异常
     */
    UNKNOWN_GATEWAY_ERROR(508,
            "error.unknownGatewayError", "UNKNOWN_GATEWAY_ERROR", "helper.info.unknownGatewayError"),

    /**
     * 该网关不接受该APi请求
     */
    API_MISMATCH_FILTER(507, "error.api.mismatch.filter", "API_MISMATCH_FILTER");

    public final int value;
    public final String code;

    public final String name;
    public final String message;


    private CheckState(int value, String code, String name) {
        this.value = value;
        this.code = code;
        this.name = name;
        this.message = "";
    }

    private CheckState(int value, String code, String name, String message) {
        this.value = value;
        this.code = code;
        this.name = name;
        this.message = message;
    }

    public int value() {
        return this.value;
    }

    public String code() {
        return this.code;
    }

}
